<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>签字</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <p>{{ !signPic ? '此处签名' : '（已签名）' }}</p>
        <div class="esign_textarea" ref="esignTextarea" v-if="!signPic">
          <vue-esign ref="esign" :height="250" :width="widthTexyarea" :isCrop="isCrop" :lineWidth="lineWidth"
                     :lineColor="lineColor" :bgColor.sync="bgColor" v-if="widthTexyarea"/>
        </div>
        <div class="esign_textarea" ref="esignTextarea" v-else>
          <img :src="signPic" alt="">
        </div>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="handleGenerate">确定</el-button>
        <el-button size="small" @click="handleReset" type="danger" plain>清除</el-button>
      </div>
    </div>
  </div>
</template>

<script>
// <!--    会签审核人 signType 1 面试签字 2 考核签字-->
export default {
  props: ['visible', 'signPic'],
  components: {},
  data() {
    return {
      dialogVisible: false,
      widthTexyarea: 0,
      lineWidth: 7,
      lineColor: '#000000',
      bgColor: '#fff',
      resultImg: '',
      isCrop: false,
      flag: true
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        let n = this;
        this.$nextTick(() => {
          n.widthTexyarea = this.$refs.esignTextarea.clientWidth;
        })
      }
    }
  },
  created() {

  },
  methods: {
    handleReset() {
      if(!this.signPic){
        this.$refs.esign.reset()
      }else{
        this.$emit('signPinFn', {pic: ''})
      }
    },
    handleGenerate() {
      let n = this
      if (this.flag) {
        this.flag = false
        this.$refs.esign.generate().then(res => {
          // this.resultImg = res // noticeStatus 1问卷 2通知
          n.$emit('signPinFn',{pic: res})
          n.closePOpup()
          n.flag = true;
        }).catch(err => {
          this.flag = true;
          console.log('未签名1', err) // 画布没有签字时会执行这里 'Not Signned'
        })
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
      this.$refs.esign.reset()
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {

  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 50%;
  height: 50%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
  z-index: 9;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.esign_textarea {
  border: 1px #999 solid;
  margin-top: 20px;
  box-shadow: 0 0 10px #dedede;
  border-radius: 3px;
  overflow: hidden;
}
</style>


